#!/bin/sh

#
# This file is released under the terms of the Artistic License.
# Please see the file LICENSE, included in this package, for details.
#
# Copyright (C) 200-2010 Mark Wong & Open Source Development Lab, Inc.
#

while getopts "o:" opt; do
	case ${opt} in
	o)
		OUTPUT=${OPTARG}
		;;
	esac
done

if [ "x${DBT5DBNAME}" = "x" ]; then
	echo "DBT5DBNAME not defined."
	exit 1
fi

if [ "x${OUTPUT}" = "x" ]; then
	echo "use -o and specify the backup file"
	exit 1;
fi

_test=`pg_restore -v Fc -a -d ${DBT5DBNAME} ${OUTPUT} | grep OK`
if [ "$_test" != "" ]; then
	echo "restore failed: $_test"
	exit 1
fi

exit 0
